import * as Router from 'koa-router';
import { IRouterContext } from 'koa-router';
import dataService from '../temporaryData/dataService';
let router=new Router();
//写拜访记录页面数据的暂存与显示
router.prefix('/api/temp');

//单个暂存拜访记录数据
router.post('/saveVisitRecoderTemporaryData',async(ctx:IRouterContext,next:any)=>{
    let rp:any=ctx.request;
    let res=rp.body;
    let s=await dataService.saveTemData(res);
    //1----------暂存数据成功      0----------暂存数据失败
    if(s.n>0){
        ctx.body={code:1};
        ctx.status=200;
    }else{
        ctx.boay={code:0}
    }
    await next();
})
//单个获取暂存的拜访记录数据
router.post('/getVisitRecoderTemporaryData',async(ctx:IRouterContext,next:any)=>{
    let rp:any=ctx.request;
    let res=rp.body;
    let data=await dataService.getTemporaryData(res.userId,res.date);
    if(data !=null){
        ctx.body=data;
        ctx.status=200;
    }else{
        // console.log('无暂存数据!!!!!');
        ctx.body=[]
    }
    await next();
})

//批量删除拜访记录暂存的数据
router.post('/deleteVisitRecoderTemporaryData',async(ctx:IRouterContext,next:any)=>{
    let rp:any=ctx.request;
    let res=rp.body;
    // console.log(res);
    await dataService.deleteTemporaryData(res.monthList);
    // console.log('清除'+res.month+'月份的暂存数据结束!!!!!!!!!!!!!!!!!');
    ctx.body={code:1};
    ctx.status=200;
    await next();
})


export default router;

